package com.qding.park.manager.timer.schedule.job;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.JobExecutionContext;
import org.quartz.JobKey;
import org.quartz.SchedulerException;
import org.springframework.stereotype.Service;

import com.baidu.disconf.client.common.annotations.DisconfUpdateService;
import com.baidu.disconf.client.common.update.IDisconfUpdate;
import com.qding.park.common.core.constant.CacheKeyThree;
import com.qding.park.common.core.redis.JedisClient;
import com.qding.park.common.core.redis.SerializeUtils;
import com.qding.park.manager.pojo.queue.QueueMsg;
import com.qding.park.manager.pojo.queue.QueueTypeEnum;
import com.qding.park.manager.timer.ParkTimerApplication;
import com.qding.park.manager.timer.conf.TaskConfig;

@Service
@DisconfUpdateService(classes = { TaskConfig.class }, itemKeys = { "task.ExpireNoticeJob.name",
		"task.ExpireNoticeJob.taskJobClass", "task.ExpireNoticeJob.cronTime" })
public class ExpireNoticeJob extends AbstractJob implements IDisconfUpdate {
	private static final Log _log = LogFactory.getLog(ParkBaseDataSyncJob.class);

	@Override
	public void reload() throws Exception {
		_log.info(TaskConfig.getTask_ExpireNoticeJob_name());
		String taskName = TaskConfig.getTask_ExpireNoticeJob_name();
		String cronTime = TaskConfig.getTask_ExpireNoticeJob_cronTime();
		super.reloadTask(taskName, cronTime);

	}

	@Override
	protected void execJob(JobExecutionContext context) {
		JobKey jobKey = context.getJobDetail().getKey();

		// 得到redis client
		JedisClient jedisClient = ParkTimerApplication.ctxUtil.getApplicationContext().getBean(JedisClient.class);

		// 用户数据同步任务
		QueueMsg expireCarSms = new QueueMsg();
		expireCarSms.setEventType(QueueTypeEnum.EXPIRE_CAR_SMS.getType());
		String userInfoMsgStr = SerializeUtils.serialize(expireCarSms);
		// 用户数据同步 消息
		jedisClient.lpush(CacheKeyThree.QUEUE_ALL, userInfoMsgStr);

	}

}
